#ifndef _Particle_Factory_H
#define _Particle_Factory_H


#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <list>


#include "objects.h"
#include "script_engine.h"


using namespace std;



enum Particle_State
{
	PS_NONE = 0,
	PS_ACTIVE,
	PS_DEAD
};

enum Particle_Type
{
	PT_NONE = 0,
	PT_PROJECTILE,
	PT_NADES,
	PT_SLUGS,
	PT_MISSLES,
};


//Particle Class
class Particles : public Objects
{
public:
	//Constructor
	Particles();
	~Particles();	


	//Load Script Driver
	 static bool  Get_DriverScript( string );


	sf::Vector2f center_point;

	//std::string name;


	int min_speed, max_speed;
	int damage;
	int life;
	int rotation_amount;

	int type;

	int amountPerCycle;
	float spread_angle;

	int blend_mode;


	//Scale amount
	sf::Vector2f scale;



		
//	Colors for Saturation
	sf::Color startingColor;
	sf::Color endingColor;
	sf::Color color;
	sf::Color changeRateColor;

	//float r, g, b, alpha;


     bool collision;

	//Get individual particle Properties
	 bool  Get_Config( string resource_dir );

	 

	 


	 //Set particles equal to each other
	 Particles& operator = ( const Particles& other )
	 {

		velocity = other.velocity;
		SetPosition( other.GetPosition() );

		angle = other.angle ;
		rotation_amount = other.rotation_amount;

		min_speed = other.min_speed;
		max_speed = other.max_speed;


		collision = other.collision;
		center_point = other.center_point;
		life = other.life;
		blend_mode = other.blend_mode;
		damage = other.damage;

		//Set colors
		startingColor = other.startingColor;
		endingColor = other.endingColor;
		color = other.color;
		changeRateColor = other.changeRateColor;

		//image stuff
		img = other.img;
		SetImage( *img );
		

        return *this;
	 }//eof


	
	 

	 //Script specific stuff
	 static bool Register_With_ScriptEngine( string );

	 void AddRef();
	 void Release();

	 bool hasDriver;
	   //For Script function
	 int DriverFunctionID;

protected:
	
	int refCount;

};


//Simple Particle system
class Particle_Factory : public Objects
{
public:

//Load all folders for Ammo
     static bool Load( string );

//Spawn p_count # of particles at Position pos
	 //different variations of emitters!
 	 virtual void Emit( Particles &type, sf::Vector2f pos, float angle = 0, int p_count = 1);
	 virtual void Emit( Particles &type, sf::Vector2f pos, int p_count = 1);

	 virtual void Emit( string type, sf::Vector2f pos, float angle = 0, int p_count = 1);
	 virtual void Emit( string type, sf::Vector2f pos, sf::Vector2f vel, float angle = 0, int p_count = 1);

	 void BaseEmit( Particles &type, sf::Vector2f pos, sf::Vector2f vel, float angle = 0, int p_count = 1);

//	 void Emit( int type_number, int p_count );


//Modify Velocity
	 virtual void Modify( sf::Vector2f new_velocity );




//Update Particle Mechanics
	 virtual void Update_Logic();
			 void Standard_Logic(Particles &p); //Logic that does not change between different particles
			 void Update_Colors(Particles &p);	//Update Color changes
			 void Map_Collision(Particles &p); //Handle map collision

	 //Randomize Colors
	 virtual void Randomize_Colors( string );


//Destroy Particle when it is useless
	 virtual void Destroy_Particle(Particles &p);

//Draw to screen
	 virtual void Draw();



	 //Get particle Type
	 static list < Particles > Get_Type() { return Type; }

	 //Get particle List
	 static vector < std::string > Get_List() { return List; }
	 


	
	 //Particle Prototypes to base emited particles off of
	 static list < Particles > Type;
	 
//Particles
	 list < Particles > p_obj;

	
private:

	//Id for each particle to call its update function from script
	static std::map<std::string, int > driverFunctIDs;
	static asIScriptContext * ctxMain;

//Get list of type folders to load
	 static bool Setup_List();
	 static bool Grab_ScriptIDs();


//Resource Directory
	 static std::string resources_directory;

//List of particle catigories
	 static std::vector < std::string > List;

};








//static std::vector < Objects > particles;



#endif
